__author__ = 'aaqqxx'
# Simple Calc v0.11
# Designed by tcalbert
# 2008.03.02
# The former version was v0.03
# Many more functions have
# been added in this version.

import appuifw
import e32
import math
appuifw.app.title=u'Simple Calc v0.11'
appuifw.app.body=appuifw.Text(u'please press the "Options" ...')
def exit_key_handler():
  app_lock.signal()
app_lock=e32.Ao_lock()
appuifw.app.exit_key_handler=exit_key_handler
def about():
  appuifw.app.body=appuifw.Text(u'Simple Calc v0.11                      Designed by tcalbert, 08.03.02. To see more detailed information, please visit        http://www.opda.net.cn')
def help():
  appuifw.app.body=appuifw.Text(u'I think there is no problem for you to use such a simple software.But if you do have problems, please write to me. My e-mail address is                     694169531@qq.com                     And also, I am waiting for your good ideas and valuable suggestions.')
def eqsubitem1():
  a=appuifw.query(u'a','float')
  if a==None:
    a=0
  if a==0:
    appuifw.note(u'a=0 is not permitted!','error')
  else:
    b=appuifw.query(u'b','float')
    c=appuifw.query(u'c','float')
    if b==None:
      b=0
    if c==None:
      c=0
    delta=math.pow(b,2)-4*a*c
    if delta<0:
      appuifw.note(u'no real root','info')
    else:
      x1=(0-b+math.sqrt(delta))/(2*a)
      x2=(0-b-math.sqrt(delta))/(2*a)
      appuifw.app.body=appuifw.Text(u'x1='+str(x1)+u'    '+u'x2='+str(x2))
def eqsubitem2():
  appuifw.note(u'not available now','info')
def eqsubitem3():
  a1=appuifw.query(u'a1','float')
  b1=appuifw.query(u'b1','float')
  c1=appuifw.query(u'c1','float')
  a2=appuifw.query(u'a2','float')
  b2=appuifw.query(u'b2','float')
  c2=appuifw.query(u'c2','float')
  if a1==None:
    a1=0.0
  if b1==None:
    b1=0.0
  if c1==None:
    c1=0.0
  if a2==None:
    a2=0.0
  if b2==None:
    b2=0.0
  if c2==None:
    c2=0.0
  delta=a1*b2-b1*a2
  if delta==0:
    appuifw.note(u'error','error')
  else:
    x=(c1*b2-b1*c2)/delta
    y=(a1*c2-c1*a2)/delta
    appuifw.app.body=appuifw.Text(u'x='+str(x)+u'    '+u'y='+str(y))
def eqsubitem4():
  a1=appuifw.query(u'a1','float')
  b1=appuifw.query(u'b1','float')
  c1=appuifw.query(u'c1','float')
  d1=appuifw.query(u'd1','float')
  a2=appuifw.query(u'a2','float')
  b2=appuifw.query(u'b2','float')
  c2=appuifw.query(u'c2','float')
  d2=appuifw.query(u'd2','float')
  a3=appuifw.query(u'a3','float')
  b3=appuifw.query(u'b3','float')
  c3=appuifw.query(u'c3','float')
  d3=appuifw.query(u'd3','float')
  if a1==None:
    a1=0.0
  if b1==None:
    b1=0.0
  if c1==None:
    c1=0.0
  if d1==None:
    d1=0.0
  if a2==None:
    a2=0.0
  if b2==None:
    b2=0.0
  if c2==None:
    c2=0.0
  if d2==None:
    d2=0.0
  if a3==None:
    a3=0.0
  if b3==None:
    b3=0.0
  if c3==None:
    c3=0.0
  if d3==None:
    d3=0.0
  delta=a1*b2*c3+a2*b3*c1+a3*c2*b1-c1*b2*a3-c2*b3*a1-c3*a2*b1
  if delta==0:
    appuifw.note(u'error','error')
  else:
    x=(d1*b2*c3+d2*b3*c1+d3*c2*b1-c1*b2*d3-c2*b3*d1-c3*d2*b1)/delta
    y=(a1*d2*c3+a2*d3*c1+a3*c2*d1-c1*d2*a3-c2*d3*a1-c3*a2*d1)/delta
    z=(a1*b2*d3+a2*b3*d1+a3*d2*b1-d1*b2*a3-d2*b3*a1-d3*a2*b1)/delta
    appuifw.app.body=appuifw.Text(u'x='+str(x)+u'    '+u'y='+str(y)+u'    '+u'z='+str(z))

def funcsubitem1():
  sin_in1=appuifw.query(u'sin','float')
  if sin_in1==None:
    print
  else:
    sin_in2=(math.pi)*(sin_in1/180)
    sin_out=math.sin(sin_in2)
    appuifw.app.body=appuifw.Text(u'sin'+str(sin_in1)+u'='+str(sin_out))
def funcsubitem2():
  cos_in1=appuifw.query(u'cos','float')
  if cos_in1==None:
    print
  else:
    cos_in2=(math.pi)*(cos_in1/180)
    cos_out=math.cos(cos_in2)
    appuifw.app.body=appuifw.Text(u'cos'+str(cos_in1)+u'='+str(cos_out))
def funcsubitem3():
  tan_in1=appuifw.query(u'tan','float')
  if tan_in1==None:
    print
  else:
    tan_in2=(math.pi)*(tan_in1/180)
    tan_out=math.tan(tan_in2)
    appuifw.app.body=appuifw.Text(u'tan'+str(tan_in1)+u'='+str(tan_out))
def funcsubitem4():
  log_e=appuifw.query(u'ln','float')
  if log_e==None:
    print
  if log_e<=0:
    appuifw.note(u'error','error')
  else:
    log_e_out=math.log(log_e)
    appuifw.app.body=appuifw.Text(u'ln'+str(log_e)+u'='+str(log_e_out))
def funcsubitem5():
  log_10=appuifw.query(u'lg','float')
  if log_10==None:
    print
  if log_10<=0:
    appuifw.note(u'error','error')
  else:
    log_10_out=(math.log(log_10))/(math.log(10))
    appuifw.app.body=appuifw.Text(u'lg'+str(log_10)+u'='+str(log_10_out))
def funcsubitem6():
  log_a=appuifw.query(u'a','float')
  if log_a==None:
    print
  if log_a<=0:
    appuifw.note(u'error','error')
  else:
    log_b=appuifw.query(u'b','float')
    if log_b==None:
      print
    if log_b<=0:
      appuifw.note(u'error','error')
    else:
      log_a_b_out=(math.log(log_b))/(math.log(log_a))
    appuifw.app.body=appuifw.Text(u'log'+u'('+str(log_a)+u')'+str(log_b)+u'='+str(log_a_b_out))
def funcsubitem7():
  base_a1=appuifw.query(u'a','float')
  base_a2=base_a1*1.0
  power_b1=appuifw.query(u'b','float')
  power_b2=power_b1*1.0
  result=math.pow(base_a2,power_b2)
  appuifw.app.body=appuifw.Text(u'('+str(base_a2)+u')'+u'^'+str(power_b2)+u'='+str(result))
appuifw.app.menu=[(u'Function',((u'sin',funcsubitem1),(u'cos',funcsubitem2),(u'tan',funcsubitem3),(u'(a)^b',funcsubitem7),(u'log',funcsubitem6),(u'ln',funcsubitem4),(u'lg',funcsubitem5))),(u'Equation',((u'x^2',eqsubitem1),(u'x^3',eqsubitem2),(u'xy',eqsubitem3),(u'xyz',eqsubitem4))),(u'help',help),(u'about',about)]
app_lock.wait()

# To be updated ...
#